package com.free.viewmover;

import java.util.ArrayList;

import android.graphics.Rect;
import android.view.ViewGroup;

import com.free.app.MoveItemLayout;

public abstract class Animator 
{
	protected float mLastTouchDeltaX;
	protected float mLastTouchDeltaY;
	protected float mLastTouchX;
	protected float mLastTouchY;
	protected Rect mUniformRect;
	protected boolean mEnableUniformSize = false;

	protected ArrayList<MoveItemLayout> mVisibleViews;
	protected ArrayList<MoveItemLayout> mNextViews = null;
	protected ArrayList<MoveItemLayout> mPreviousViews = null;

	public void initVisibleView(int viewCount, int nextCount, int previousCount )
	{
		assert(viewCount > 0 && nextCount > 0 && previousCount > 0);
		
		mVisibleViews = new ArrayList<MoveItemLayout>(viewCount);
		for( int i = 0 ; i < viewCount ; i++ )
			mVisibleViews.add(i, null);
			
		mNextViews = new ArrayList<MoveItemLayout>(nextCount);
		for( int i = 0 ; i < nextCount ; i++ )
			mNextViews.add(i, null);
		
		mPreviousViews = new ArrayList<MoveItemLayout>(previousCount);
		for( int i = 0 ; i < previousCount ; i++ )
			mPreviousViews.add(i, null);
	}
	
	public void setVisibleView(int index, MoveItemLayout view)
	{
		if( index < 0 && index >= mVisibleViews.size() )
			return;
		
		mVisibleViews.set(index, view);
	}	
	
	public void setNextView(int index, MoveItemLayout view)
	{
		if( index < 0 && index >= mNextViews.size() )
			return;
		
		mNextViews.set(index, view);
	}
	
	public void setPreviousView(int index, MoveItemLayout view)
	{
		if( index < 0 && index >= mPreviousViews.size() )
			return;
		
		mPreviousViews.set(index, view);
	}
	
	public int getVisibleViewSize()
	{
		return mVisibleViews.size();
	}
	
	public int getNextViewSize()
	{
		return mNextViews.size();
	}
	
	public int getPreviousViewSize()
	{
		return mPreviousViews.size();
	}
	
	public Rect getUniformRect()
	{
		return mUniformRect;
	}
	
	public void enableUniformRect(boolean isEnable)
	{
		mEnableUniformSize = isEnable;
		if( mEnableUniformSize && mUniformRect == null )
		{
			mUniformRect = new Rect();
		}			
	}
	
	public void enableUniformRect(boolean isEnable, ViewGroup root, Rect emptyRect, int l,
			int t, int r, int b)
	{
		enableUniformRect(isEnable);
		if( isEnable )
			setUniformRect(root, emptyRect, l, t, r, b);
	}
	
	protected abstract void setUniformRect(ViewGroup root, Rect emptyRect, int l,
			int t, int r, int b);
	
	public void startMove(float x, float y)
	{
		mLastTouchDeltaX = 0;
		mLastTouchDeltaY = 0;
		mLastTouchX = x;
		mLastTouchY = y;
	}
	
	public void touchMoving(float x, float y)
	{
		
	}
	
	public boolean endMove(float x, float y)
	{
		return false;
	}
}
